home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / uwin / cassette / printvie.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  8.3 KB  |  310 lines

  1. // Copyright (c) 1994, William Wagner
  2. // All Rights reserved.
  3. //
  4. // This source is a portion of a shareware program.  It may be distributed
  5. // only in its entirety.  The copyright statements must be included with any 
  6. // reproduction of this source.
  7. // 
  8.  
  9. // printvie.cpp : implementation file
  10. //
  11.  
  12. #include "stdafx.h"
  13. #include "cassette.h"
  14. #include "printvie.h"
  15.  
  16. #include "cassedoc.h"
  17.  
  18. //Constants for the sizes of the visual effects on the tape J-Card.
  19. const int TAPE_X = 390;
  20. const int TAPE_Y = 375;
  21. const int FRONT_Y = 260;
  22. const int FACE_Y = 50;
  23.  
  24. const int SIDE_2 = 200;
  25. const int BORDER = 20;
  26. const int TEXT_XSPACING = 11;
  27. const int TEXT_YSPACING = 5;
  28. const int OVERLAP = 50;
  29.  
  30. #ifdef _DEBUG
  31. #undef THIS_FILE
  32. static char BASED_CODE THIS_FILE[] = __FILE__;
  33. #endif
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CPrintView
  37.  
  38. IMPLEMENT_DYNCREATE(CPrintView, CScrollView)
  39.  
  40. //Initialize the const rectangles.
  41. CPrintView::CPrintView() : 
  42.     m_Side1Rect (BORDER+TEXT_XSPACING, -(BORDER + TEXT_YSPACING), 
  43.         BORDER + SIDE_2 + OVERLAP, -(BORDER+FRONT_Y-TEXT_YSPACING)),
  44.     m_Side2Rect (BORDER + SIDE_2 - OVERLAP, -(BORDER + TEXT_YSPACING),
  45.         BORDER + TAPE_X - TEXT_XSPACING, -(BORDER+FRONT_Y-TEXT_YSPACING)),
  46.     m_ArtistTextRect (BORDER+TEXT_XSPACING, -(BORDER+FRONT_Y+TEXT_YSPACING), 
  47.         BORDER + TAPE_X - TEXT_XSPACING, -(BORDER+FRONT_Y+FACE_Y-TEXT_YSPACING)),
  48.     m_AlbumTextRect (BORDER+TEXT_XSPACING, -(BORDER+FRONT_Y+TEXT_YSPACING),
  49.         BORDER + TAPE_X - TEXT_XSPACING, -(BORDER+FRONT_Y+FACE_Y-TEXT_YSPACING)),
  50.     m_NotesTextRect (BORDER+TEXT_XSPACING, -(BORDER+FRONT_Y+FACE_Y+TEXT_YSPACING),
  51.         BORDER+TAPE_X - TEXT_XSPACING, -(BORDER+TAPE_Y-TEXT_YSPACING)),
  52.     m_SongsRect (BORDER, -(BORDER+FRONT_Y), BORDER + TAPE_X, -BORDER),
  53.     m_ArtistRect (BORDER, -(BORDER+FRONT_Y+FACE_Y), BORDER + SIDE_2,
  54.         -(BORDER+FRONT_Y)),
  55.     m_AlbumRect (BORDER+SIDE_2, -(BORDER+FRONT_Y+FACE_Y), BORDER + TAPE_X,
  56.         -(BORDER+FRONT_Y)),
  57.     m_NotesRect (BORDER, -(BORDER+TAPE_Y), BORDER+TAPE_X,
  58.     -(BORDER+FRONT_Y+FACE_Y))
  59. {
  60. }
  61.  
  62. //Destroy things.  No pointers, so it doesn't matter.
  63. CPrintView::~CPrintView()
  64. {
  65. }
  66.  
  67. BEGIN_MESSAGE_MAP(CPrintView, CScrollView)
  68.     //{{AFX_MSG_MAP(CPrintView)
  69.     ON_WM_LBUTTONDBLCLK()
  70.     //}}AFX_MSG_MAP
  71.     ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  72.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  73. END_MESSAGE_MAP()
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CPrintView drawing
  77. #ifdef _DEBUG
  78. CCassetteDoc* CPrintView::GetDocument() // non-debug version is inline
  79. {
  80. ASSERT_VALID (this);
  81. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCassetteDoc)));
  82. return (CCassetteDoc*) m_pDocument;
  83. }
  84. #endif
  85.  
  86. //The initial Update.
  87. // Set the scroll sizes.  The sizes are size of the tape pluse
  88. // twice the border.
  89. //Don't call the base class, that passes a NULL OnUpdate.
  90. //Invalidate the entire window instead.
  91. void CPrintView::OnInitialUpdate()
  92. {
  93. ASSERT_VALID (this);
  94.  
  95. CSize sizeTotal (TAPE_X + 2 * BORDER, TAPE_Y + 2 * BORDER);
  96.  
  97. SetScrollSizes(MM_LOENGLISH, sizeTotal);
  98. InvalidateRect (NULL);
  99. }
  100.  
  101. //Handle the updates.
  102. // So, depending on the rectangle that has changed,
  103. // invalidate the proper parts of the window.  That will
  104. // cause the window to be redrawn.
  105. void CPrintView::OnUpdate (CView*, LPARAM lHint, CObject*)
  106. {
  107. ASSERT_VALID (this);
  108.  
  109. CRect DeviceRect (0,0,0,0);
  110. CDC* pDC = GetDC ();
  111.  
  112. ASSERT_VALID (pDC);
  113.  
  114. pDC->SetMapMode (MM_LOENGLISH);
  115.  
  116. switch (lHint)
  117.     {
  118.     case ALBUM1_CHANGE:
  119.     case ALBUM2_CHANGE:
  120.     case FONT_ALBUM_CHANGE:
  121.         DeviceRect = m_AlbumTextRect;
  122.         break;
  123.         
  124.     case ARTIST1_CHANGE:
  125.     case ARTIST2_CHANGE:   
  126.     case FONT_ARTIST_CHANGE:
  127.         DeviceRect = m_ArtistTextRect;
  128.         break;
  129.         
  130.     case SONGS1_CHANGE:
  131.         DeviceRect = m_Side1Rect;
  132.         break;
  133.         
  134.     case SONGS2_CHANGE:
  135.         DeviceRect = m_Side2Rect;
  136.         break;
  137.     
  138.     case NOTES_CHANGE:
  139.     case FONT_NOTES_CHANGE:
  140.         DeviceRect = m_NotesTextRect;
  141.         break;
  142.  
  143.     case FONT_SONGS_CHANGE:
  144.         {
  145.         //This is slightly different, there are two different 
  146.         //rectangles that need to be invalidated/
  147.         DeviceRect = m_Side1Rect;
  148.         pDC->LPtoDP (DeviceRect);
  149.         InvalidateRect (DeviceRect);
  150.         DeviceRect = m_Side2Rect;
  151.         }
  152.         break;
  153.         
  154.     default:
  155.         ASSERT (FALSE);
  156.     }
  157. pDC->LPtoDP (DeviceRect);
  158. ReleaseDC (pDC);
  159. InvalidateRect (DeviceRect);
  160. }
  161.  
  162. //Draw the lines surrounding the tape label.
  163. // Just some GDI work.
  164. void CPrintView::DrawLines (CDC* pDC) const
  165. {
  166. ASSERT_VALID (this);
  167. ASSERT_VALID (pDC);
  168.  
  169. // Draw the border
  170. CPen OutLinePen(PS_SOLID, 7, GetSysColor (COLOR_WINDOWTEXT));
  171. CPen InteriorLinePen (PS_SOLID, 5, GetSysColor (COLOR_WINDOWTEXT));
  172.  
  173. ASSERT_VALID (&OutLinePen);
  174. ASSERT_VALID (&InteriorLinePen);
  175.  
  176. CPen* pOldPen;
  177.     
  178. pOldPen = pDC->SelectObject (&OutLinePen);
  179.  
  180. ASSERT_VALID (pOldPen);
  181.  
  182. pDC->MoveTo (BORDER,-BORDER);
  183. pDC->LineTo (TAPE_X+BORDER , -BORDER);    
  184. pDC->LineTo (TAPE_X+BORDER, -(TAPE_Y+BORDER));
  185. pDC->LineTo (BORDER, -(TAPE_Y+BORDER));
  186. pDC->LineTo (BORDER, -BORDER);
  187.     
  188. // Middle Lines
  189. pDC->SelectObject (&InteriorLinePen);
  190. pDC->MoveTo (BORDER, -(BORDER + FRONT_Y));
  191. pDC->LineTo (TAPE_X+BORDER, -(BORDER + FRONT_Y));
  192. pDC->MoveTo (BORDER, -(BORDER + FRONT_Y + FACE_Y));
  193. pDC->LineTo (TAPE_X+BORDER, -(BORDER + FRONT_Y + FACE_Y));
  194. pDC->SelectObject (pOldPen);
  195. }
  196.  
  197. //Draw the text for this J Card.
  198. // Like draw lines, just some GDI programming.
  199. void CPrintView::DrawTextData (CDC* pDC, const CCassetteDoc* pDoc) const
  200. {
  201. ASSERT_VALID (this);
  202. ASSERT_VALID (pDC);
  203. ASSERT_VALID (pDoc);
  204.  
  205. CFont SongsFont;
  206. CFont ArtistFont;
  207. CFont AlbumFont;
  208. CFont NotesFont;
  209. CFont* pOldFont;
  210.  
  211. SongsFont.CreateFontIndirect (&(pDoc->m_lfontSongs));
  212. ArtistFont.CreateFontIndirect (&(pDoc->m_lfontArtist));
  213. AlbumFont.CreateFontIndirect (&(pDoc->m_lfontAlbum));
  214. NotesFont.CreateFontIndirect (&(pDoc->m_lfontNotes));
  215.  
  216. ASSERT_VALID (&SongsFont);
  217. ASSERT_VALID (&ArtistFont);
  218. ASSERT_VALID (&AlbumFont);
  219. ASSERT_VALID (&NotesFont);
  220.  
  221. // Songs on side 1
  222. pOldFont = pDC->SelectObject (&SongsFont);
  223. ASSERT_VALID (pOldFont);
  224.  
  225. pDC->DrawText (pDoc->m_csSongs1, pDoc->m_csSongs1.GetLength (), m_Side1Rect, DT_LEFT); 
  226. pDC->DrawText (pDoc->m_csSongs2, pDoc->m_csSongs2.GetLength (), m_Side2Rect, DT_RIGHT);    
  227.  
  228. // Artist rectangle
  229. pDC->SelectObject (&ArtistFont);
  230. CString Artists = pDoc->m_csArtist1;
  231. if (!pDoc->m_csArtist2.IsEmpty())
  232.     Artists += "\n" + pDoc->m_csArtist2;
  233. pDC->DrawText (Artists, Artists.GetLength (), m_ArtistTextRect, DT_LEFT);    
  234.  
  235. // Album rectangle
  236. pDC->SelectObject (&AlbumFont);
  237. CString Albums = pDoc->m_csAlbum1;
  238. if (!pDoc->m_csAlbum2.IsEmpty())
  239.     Albums += "\n" + pDoc->m_csAlbum2;
  240. pDC->DrawText (Albums, Albums.GetLength (), m_AlbumTextRect, DT_RIGHT);
  241.  
  242. // Notes rectangle
  243. pDC->SelectObject (&NotesFont);
  244. pDC->DrawText (pDoc->m_csNotes, pDoc->m_csNotes.GetLength (), m_NotesTextRect, DT_CENTER);    
  245.  
  246. //Restore the original font.
  247. pDC->SelectObject (pOldFont);
  248. }
  249.  
  250. //Handle the drawing.  
  251. //Get a pointer to the document.  Call some
  252. //little helper functions to put things on the screen.
  253. void CPrintView::OnDraw(CDC* pDC)
  254. {
  255. ASSERT_VALID (this);
  256. ASSERT_VALID (pDC);
  257.  
  258. CCassetteDoc* pDoc = GetDocument();
  259.  
  260. ASSERT_VALID (pDoc);
  261.  
  262. DrawLines (pDC);
  263. DrawTextData (pDC, pDoc);
  264.  
  265. ASSERT_VALID (pDoc);
  266. ASSERT_VALID (pDC);
  267. }
  268.  
  269. //Prepare the printing.  We only have one page.
  270. // So, set the max pages.  
  271. BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
  272. {
  273. ASSERT_VALID (this);
  274. pInfo->SetMaxPage (1);
  275. return DoPreparePrinting(pInfo);
  276. }
  277.  
  278. /////////////////////////////////////////////////////////////////////////////
  279. // CPrintView message handlers
  280.  
  281. //Double Click handlers.
  282. // Determine if the user clicked on one of the hit rectangles.
  283. // If so, call the document's print command handler.
  284. void CPrintView::OnLButtonDblClk(UINT , CPoint point)
  285. {
  286. ASSERT_VALID (this);
  287. int WhichFont = 0;
  288.  
  289. CDC* pDC = GetDC ();
  290.  
  291. ASSERT_VALID (pDC);
  292.  
  293. pDC->SetMapMode (MM_LOENGLISH);
  294. pDC->DPtoLP (&point);
  295. ReleaseDC (pDC);
  296.  
  297. if (m_SongsRect.PtInRect (point))
  298.     WhichFont = FONT_SONGS_CHANGE;
  299. else if (m_ArtistRect.PtInRect (point))
  300.     WhichFont = FONT_ARTIST_CHANGE;
  301. else if (m_AlbumRect.PtInRect (point))
  302.     WhichFont = FONT_ALBUM_CHANGE;
  303. else if (m_NotesRect.PtInRect (point))
  304.     WhichFont = FONT_NOTES_CHANGE;
  305. else
  306.     return;
  307. ASSERT_VALID (GetDocument ());
  308. GetDocument ()->DoFontCommand (WhichFont);
  309. }
  310.